#include "ItemHealth.h"

ItemHealth::ItemHealth()
{
    x = 0;
    y = 0;
    motionX = 0;
    motionY = 0;

    data = new ItemHealthData;
    data->mass = 0;
    data->speed = 0;
    static_cast<ItemHealthData*>(data)->useOnPickup = false;
    static_cast<ItemHealthData*>(data)->asPercent = false;
    static_cast<ItemHealthData*>(data)->healthRegen = 0;

    needsRemoval = false;
}

Entity* ItemHealth::clone()
{
    return new ItemHealth(*this);
}

void ItemHealth::onUse(PlayerEntity* player)
{
    int health = static_cast<ItemHealthData*>(data)->healthRegen;
    if(static_cast<ItemHealthData*>(data)->asPercent)
    {
        health = health * player->getMaxHP() / 100;
    }
    player->heal(health);
}

ItemHealth::~ItemHealth()
{
    //dtor
}

ItemHealth* ItemHealth::setHealthRegen(int i)
{
    static_cast<ItemHealthData*>(data)->healthRegen = i;
    return this;
}

ItemHealth* ItemHealth::setAsPercent(bool b)
{
    static_cast<ItemHealthData*>(data)->asPercent = b;
    return this;
}
